package com.shxc.smarttrade.account.adapter;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.shxc.smarttrade.R;

import java.util.List;

/**
 * 帮助中心 - 选择客服
 */
public class CustomerPagerAdapter extends PagerAdapter {
    private LayoutInflater inflater;
    private Context c;
    private List<Integer> imageResourseList;
    private Handler mHandler;
    public CustomerPagerAdapter(LayoutInflater inflater, Context c,
                                List<Integer> list,Handler handler
    ) {
        this.c = c;
        this.inflater = inflater;
        imageResourseList = list;
        mHandler = handler;
    }

    @Override
    public int getCount() {
        return 3;
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0.equals(arg1);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager) container).removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        View convertView = inflater.inflate(R.layout.pager_help_center, null);

        ImageView imageview = convertView.findViewById(R.id.imageview);
        imageview.setImageResource(imageResourseList.get(position));
        ImageView close_imageview = convertView.findViewById(R.id.close_imageview);
        View click_view = convertView.findViewById(R.id.click_view);

        //关闭
        close_imageview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mHandler.sendEmptyMessage(2);
            }
        });
        //点击
        click_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Message msg = new Message();
                msg.what = 3;
                msg.obj = position;
                mHandler.sendMessage(msg);
            }
        });

        ((ViewPager) container).addView(convertView);
        return convertView;
    }

}
